from django import forms
from django.core import validators
from django.forms.widgets import DateInput, CheckboxSelectMultiple
from django.forms.extras.widgets import SelectDateWidget 
from django.contrib.auth.models import User

from CostCalc.models import EventProfile, EventExpenseProfile, UserProfile, SubgroupExpense
import datetime
 
 
class RegistrationForm(forms.Form):
    username = forms.CharField(label="Username" )
    email = forms.EmailField(label="Email Address"  )
    password = forms.CharField( widget=forms.PasswordInput, label="Password" )    

    def save(self, new_data):
        user = User.objects.create_user(new_data['username'],
                                     new_data['email'],
                                     new_data['password'])
        user.save()
        return user
    
class LoginForm(forms.Form):
    username = forms.CharField(label = "Username")
    password = forms.CharField( widget=forms.PasswordInput, label="Password" )    

#class CreateEventForm(forms.Form):
#    eventStartDate = forms.DateField(widget = SelectDateWidget())
#    eventEndDate= forms.DateField(widget = SelectDateWidget())
#    eventName = forms.CharField(max_length = 32)
#    
#    def save(self, new_data):
#        TP = EventProfile(eventStartDate = new_data['eventStartDate'],
#                            eventEndDate = new_data['eventEndDate'],
#                            eventName = new_data['eventName'])
#        TP.save()
#        return TP
#    
#    
#class EventExpenseForm(forms.Form):
#    #expenseOwner = forms.CharField(label="Person Owed Money", choices=TITLE_CHOICES)
#    expenseName = forms.CharField(label="Expense Name" )
#    expenseAmount = forms.FloatField(label="Expense Amount")
#    expenseDate = forms.DateField(widget = SelectDateWidget())
#    
#    def save(self, new_data, userId, Event):
#        Expense = EventExpenseProfile(expenseName = new_data['expenseName'],
#                                          expenseAmount = new_data['expenseAmount'],
#                                          expenseDate = new_data['expenseDate'],
#                                          expenseAddedDate = new_data['expenseDate'],
#                                          expenseOwner_id = userId,
#                                          expenseEvent = Event)
#        
#        Expense.save()
#        return Expense
#    
#class SetPeopleOnEventForm(forms.Form):
#    usersAttended = forms.MultipleChoiceField(required=True,
#        widget=CheckboxSelectMultiple, choices=())
#    def __init__(self, Users, *args, **kwargs):
#        super(SetPeopleOnEventForm, self).__init__(*args, **kwargs)
#        if Users != None:
#            Choices = ()
#            #Choices = ((1,"1"),(2,"2"))
#            for U in Users:
#                Choices += ((int(U.id), U.user.username)),
#            self.fields["usersAttended"].choices = Choices
#    def GetSelectedIds(self, new_data):
#        return new_data["usersAttended"]
#    
#class SetDatesOnEventsForm(forms.Form):
#    datesAttended = forms.MultipleChoiceField(required=True,
#        widget=CheckboxSelectMultiple, choices=())
#    def __init__(self, Dates_Prop, *args, **kwargs):
#        super(SetDatesOnEventsForm, self).__init__(*args, **kwargs)
#        Choices = ()
#        i = 0
#        while i < len(Dates_Prop[0]):
#            Choices += (Dates_Prop[0][i], Dates_Prop[0][i]),
#            i += 1
#        self.fields["datesAttended"].choices = Choices
#    def GetSelectedDates(self, new_data):
#        return new_data["datesAttended"]
#        
#class SubGroupExpenseForm(forms.Form):
#    subgroupExpenseName = forms.CharField(label="Subgroup Expense Name" )
#    subgroupExpenseAmount = forms.FloatField(label="Expense Amount")
#    subgroupExpenseDate = forms.DateField(widget = SelectDateWidget())
#    subgroupUsers = forms.MultipleChoiceField(required=True,
#        widget=CheckboxSelectMultiple, choices=())
#    def __init__(self, Users, *args, **kwargs):
#        super(SubGroupExpenseForm, self).__init__(*args, **kwargs)
#        Choices = ()
#        
#        for U in Users:
#                Choices += ((int(U.user.id), U.user.user.username)),
#        self.fields["subgroupUsers"].choices = Choices
#    def GetSelectedIds(self, new_data):
#        return new_data["subgroupUsers"]
#    
#    #
#    #def Save(self, nex_data, Creator, Event):
#    #    SGE = SubgroupExpense(subgroupExpenseName = ['subgroupExpenseName'],
#    #                          self.
#    #        
#    #    )
#    
#    
#    


